//
// Created by Administrator on 2022/1/10.
//

#include <stdio.h>

void ReverseArray(int *array, int length);

void SortArray(int *array, int length);

int main(void) {
    int array[22] = {2, 1, 5, 6, 8, 78, 4448, 1, 54, 91, 184, 894, 651, 198, 4987, 897, 1, 1, 34, 89, 98, 1};
    //遍历数组
    for (int i = 0; i < 22; ++i) {
        printf("%d ", array[i]);
    }
    printf("\n");
    //倒序并输出
    ReverseArray(array, 22);
    for (int i = 0; i < 22; ++i) {
        printf("%d ", array[i]);
    }
    //换行
    printf("\n");
    //倒序在输出
    ReverseArray(array, 22);
    for (int i = 0; i < 22; ++i) {
        printf("%d ", array[i]);
    }
    //换行
    printf("\n");
    //排序在输出
    SortArray(array, 22);
    for (int i = 0; i < 22; ++i) {
        printf("%d ", array[i]);
    }
    return 0;
}

/**
 * 倒序输出
 * @param array
 * @param length
 */
void ReverseArray(int *array, int length) {
    for (int i = 0; i < length / 2; ++i) {
        int temp = array[i];
        array[i] = array[length - i - 1];
        array[length -1 - i] = temp;
    }
}

/**
 * 数组的排序
 * @param array
 * @param length
 */
void SortArray(int *array, int length) {
    for (int i = 0; i < length; ++i) {
        for (int j = i+1; j < length; ++j) {
            int left = array[i];
            int right = array[j];
            if (left > right) {
                int temp = left;
                array[i] = array[j];
                array[j] = temp;
            }
        }
    }
}
